<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>   
<%@page import="com.etc.controller.*" %>
<%@page import="com.etc.entity.Message" %>
<%@page import="com.etc.dao.*" %>
<%@page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>羔羊论坛</title>
<link rel="icon" type="image/x-icon" href="img/sheep.ico" />
<link rel="stylesheet" type="text/css" href="css/showmessage.css">
<style>
.tip{text-align:center;font-size:24px;font-weight:450}
.tip a{text-decoration:none;color:blue}
.tip a:hover{font-weight:500;color:purple}
</style>
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");
	List<Message> list = (List<Message>)request.getSession().getAttribute("listMessage");
	String search = (String)request.getSession().getAttribute("search");
	String username = (String)request.getSession().getAttribute("username");
	//int pageno =(Integer)(request.getAttribute("pageNo"));
%>
<c:if test="${pageCount>0}">
<br>
<ul>
<%
	if(list.size()>0)
	{
%>
	<%	
	int xuhao=0;
		for(int i=0;i<list.size();i++)
		{
		 		if((list.get(i).getStatus()=="正常"||list.get(i).getStatus().equals("正常")))
		 		{
		 				xuhao+=1;
		 				out.print("<li><a href='AnsMessageServlet?am=detail&id="+list.get(i).getId()+"'><p class='title'>"+xuhao+"&nbsp;&nbsp;"+list.get(i).getTitle()+"&nbsp;<font class='date'>"+list.get(i).getDate()+"</font><font class='username'>&nbsp;&nbsp;&nbsp;"+list.get(i).getUsername()+"</font></p></a></li>");
		 		}
		}
	%>
	</ul>
	
	<div style="height:50px;line-height:50px;text-align:center;">
	
	  <c:if test="${pageNo>1}">
	    <a href="MessageServlet?pageNo=1" class="s">第一页</a>
	    <a href="MessageServlet?pageNo=${pageNo-1}" class="s">上一页</a>
	  </c:if>
	  
	  <c:if test="${pageNo==1}">
	    <font color="black"><b>第一页</b></font>
	    <font color="black"><b>上一页</b></font>
	  </c:if>
	  
	  <c:if test="${pageCount>0}">
	  	<%
	  		int pagecount = (int)request.getAttribute("pageCount");
	  		int pageno = (int)request.getAttribute("pageNo");
	//   		for(int i=0;i<pagecount;i++)
	//   		{
	//   			out.print("<a href=\"MessageServlet?pageNo="+(i+1)+"\" class=\"s\">"+(i+1)+"  </a>");
	//   		}
	  		
	  		if(pageno>=3)
	  			for(int i=pageno-2;i<pageno;i++)
	  	  		{
	  	  			out.print("<a href=\"MessageServlet?pageNo="+i+"\" class=\"s\">"+i+"  </a>");
	  	  		}
	  		else
	  			for(int i=1;i<pageno;i++)
	  	  		{
	  	  			out.print("<a href=\"MessageServlet?pageNo="+i+"\" class=\"s\">"+i+"  </a>");
	  	  		}
	  		out.print("<font color='purple'>"+pageno+" </font>");
	  		if(pageno+2<=pagecount)
		  		for(int i=pageno+1;i<=pageno+2;i++)
		  		{
	  	  			out.print("<a href=\"MessageServlet?pageNo="+i+"\" class=\"s\">"+i+"  </a>");
		  		}
	  		else
	  			for(int i=pageno+1;i<=pagecount;i++)
	  	  		{
	  	  			out.print("<a href=\"MessageServlet?pageNo="+i+"\" class=\"s\">"+i+"  </a>");
	  	  		}
	  	%>
	  </c:if>
	   
	  <c:if test="${pageNo!=pageCount}">
	    <a href="MessageServlet?pageNo=${pageNo+1}" class="s">下一页</a>
	    <a href="MessageServlet?pageNo=${pageCount}" class="s">最后一页</a>
	  </c:if>
	  
	  <c:if test="${pageNo==pageCount}">
	    <font color="black"><b>下一页</b></font>
	    <font color="black"><b>最后一页</b></font>
	  </c:if>
	  
	</div>
<%
	}
	else
	{
		if(username==null||"".equals(username))
			out.print("<p class='tip'>当前没有该类型的帖子</p>");
		else
			out.print("<p class='tip'>当前没有该类型的帖子&nbsp<a href='user_info.jsp' target='_parent'>去发一条</a></p>");
	}
%>
	</c:if>

</body>
</html>